<template>
  <img v-if="url" :src="url" class="dicon-img" />
</template>

<script>
import defaultIcon from '../../../assets/images/component-icon.png'

export default {
  props: {
    src: {
      default: ''
    }
  },
  data () {
    return {
      url: defaultIcon
    }
  },

  watch: {
    src () {
      this.syncUrl()
    }
  },

  methods: {
    // 同步地址
    syncUrl () {
      let img = document.createElement('img')
      img.onload = () => {
        this.url = this.src
      }
      img.src = this.src
    }
  },

  beforeMount () {
    this.syncUrl()
  }
}
</script>

<style scoped>
.dicon-img {
  max-width: 100%;
  max-height: 100%;
}
</style>
